<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>新增积分规则</title>
<%@include file="../collect/meta.jsp"%>
<style type="text/css">
.tbinput {
	width: 180px;
	height: 25px;
	font-size: 14px;
	background-color: #FFFFCC;
}
</style>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<link rel="stylesheet" href="css/Inputstyle.css" type="text/css"></link>
<link rel="stylesheet" href="css/enterpriseintegralrule.css"
	type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>积分管理</li>
							<li><a href="integralrule!watchEnterpriseIntegralRule">积分规则</a>
							</li>
							<li>积分等级</li>
							<li>新增积分规则</li>
						</ul>
						<!-- .breadcrumb -->
					</div>
					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<div class="tabbable">
									<ul class="nav nav-tabs" id="myTab">
										<li class="active"><a
											href="integralrule!watchEnterpriseIntegralRule">积分等级</a>
										</li>
										<li><a href="bGiveRule!entrygiveValue">注册时积分规则</a>
										</li>
										<li><a href="bGiveRule!watchBgiveRule">时间段规则</a>
										</li>
									</ul>
								</div>
								<form action="integralrule!addEnterpriseIntegralRule"
									name="addRule" method="post">
									<div align="center">
										<div class="integrateName">
											<label for="one">积分名:&nbsp;</label> <input type="text"
												class="input" id="one" name="enterpriseIntegralRule.name" />
											<div id="contentone" class="cont1"></div>
											<input type="hidden" id="oneFlag" value="0">
										</div>
										<div class="common">
											<label for="two">积分段下限:&nbsp;</label> <input type="text"
												class="input" id="two"
												name="enterpriseIntegralRule.minValue" />
											<div id="contenttwo" class="cont2"></div>
											<input type="hidden" id="twoFlag" value="0">
										</div>
										<div class="common">
											<label for="three">积分段上限:&nbsp;</label> <input type="text"
												class="input" id="three"
												name="enterpriseIntegralRule.maxValue" />
											<div id="contentthree" class="cont2"></div>
											<input type="hidden" id="threeFlag" value="0">
										</div>
										<div class="explain">
											<label for="fover">说明:&nbsp;</label> <input type="text"
												class="input" id="fover"
												name="enterpriseIntegralRule.descirption" />
											<div id="contentfour" class="cont3"></div>
										</div>
										<div id="btn-team">
											<input type="button" class="btn btn-primary radius" id="but"
												value="添加" /> <a class="btn btn-primary radius"
												href="integralrule!watchEnterpriseIntegralRule">返回</a>
										</div>
									</div>
								</form>
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
				<!-- /.main-content -->
			</div>
			<!-- /.main-container-inner -->
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<!-- /.main-container -->
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>

	<script type="text/javascript">
		$(document)
				.ready(
						function() {
							var nu = /\s/;
							var str = /[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/;
							var intr = /^\d+$/;
							$("input[id='one']").focus(function() {
								$(this).addClass("tbinput");
								$("div[id='contentone']").text("");
							});
							$("input[id='one']").blur(
									function() {
										$(this).removeClass("tbinput");
										var one = $(this).val();
										if (!nu.test(one) && !str.test(one)) {
											if (one.length != 0) {
												$("div[id='contentone']").text(
														" 确认").removeClass(
														"error").addClass(
														"success");
												$("#oneFlag").val("1");
											} else {
												$("div[id='contentone']").text(
														" 必填").removeClass(
														"success").addClass(
														"error");
												$("#oneFlag").val("0");
											}
										} else {
											$("div[id='contentone']").text(
													"含有特殊字符").removeClass(
													"success")
													.addClass("error");
											$("#oneFlag").val("0");
										}
									});
							$("input[id='two']").focus(function() {
								$(this).addClass("tbinput");
								$("div[id='contenttwo']").text("");
							});
							$("input[id='two']").blur(
									function() {
										$(this).removeClass("tbinput");
										var one = $(this).val();
										if (one.length == 0) {
											$("div[id='contenttwo']")
													.text("必填").removeClass(
															"success")
													.addClass("error");
											$("#twoFlag").val("0");
										} else {
											if (intr.test(one)) {
												$("div[id='contenttwo']").text(
														"确认").removeClass(
														"error").addClass(
														"success");
												$("#twoFlag").val("1");
											} else {
												$("div[id='contenttwo']").text(
														"不是正确的正整数格式")
														.removeClass("success")
														.addClass("error");
												$("#twoFlag").val("0");
											}
										}
									});
							$("input[id='three']").focus(function() {
								$(this).addClass("tbinput");
								$("div[id='contentthree']").text("");
							});
							$("input[id='three']").blur(
									function() {
										$(this).removeClass("tbinput");
										var one = $(this).val();
										if (one.length == 0) {
											$("div[id='contentthree']").text(
													"必填")
													.removeClass("success")
													.addClass("error");
											$("#threeFlag").val("0");
										} else {
											if (intr.test(one)) {
												$("div[id='contentthree']")
														.text("确认")
														.removeClass("error")
														.addClass("success");
												$("#threeFlag").val("1");
											} else {
												$("div[id='contentthree']")
														.text("不是正确的正整数格式")
														.removeClass("success")
														.addClass("error");
												$("#threeFlag").val("0");
											}
										}
									});
							$("input[id='fover']").focus(function() {
								$(this).addClass("tbinput");
								$("div[id='contentfour']").text("");
							});
							$("input[id='fover']")
									.blur(
											function() {
												$(this).removeClass("tbinput");
												var one = $(this).val();

												if (one.length != 0) {
													if (!str.test(one)
															&& !nu.test(one)) {
														$(
																"div[id='contentfour']")
																.text("确认")
																.removeClass(
																		"error")
																.addClass(
																		"success");
													} else {
														$(
																"div[id='contentfour']")
																.text("含有特殊字符")
																.removeClass(
																		"success")
																.addClass(
																		"error");
													}
												} else {
													$("div[id='contentfour']")
															.text("确认")
															.removeClass(
																	"error")
															.addClass("success");
												}

											});
							$("#but")
									.click(
											function() {
												var one = $("#oneFlag").val();
												var two = $("#twoFlag").val();
												var three = $("#threeFlag").val();

												var min = $("#two").val();
												var max = $("#three").val();

												if (parseInt(min) >= parseInt(max)) {
													alert("积分下限不能大于或等于积分上限");
													return false;
												}
												
												if (one == 1 && two == 1 && three == 1) {
													var sub = true;
													$
															.ajax({
																async : false,
																url : "integralrule!verifyIntegralRule",
																type : "post",
																data : {
																	"minValue" : $(
																			"#two")
																			.val(),
																	"maxValue" : $(
																			"#three")
																			.val()
																},
																datatype : "json",
																success : function(
																		data) {
																	var d = $.parseJSON(data);
																	var b = d.temp;
																	if (b == 'error') {
																		sub = false;
																		alert("积分上下限已存在");
																	} else {
																		sub = true;
																	}
																},
																error : function(
																		request) {
																	alert("Connection error");
																}
															});

													if (sub) {
														$(
																"form[name='addRule']")
																.submit();
													}
												} else {
													alert("请完善以上信息");
													return false;
												}
											});
						});
		//防收回；积分规则：$新增积分规则
		$('.jifenguanli > ul').show();
		$('.jifenguanli > ul > li > a').eq(0).css("color", "red");
	</script>
</body>
</html>